﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "font.h"

#include <QFileDialog>
#include <QFile>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    fontPath = "";
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_getAscIIFontBtn_clicked()
{
    fontPath = QFileDialog::getSaveFileName(0, u8"save font file", "/", "dat(*.dat)");

    QFile file(fontPath);
    if(file.open(QIODevice::ReadWrite)) {
        QDataStream out(&file);

        for(int i = 0; i < 95; i++) {
            for(int j = 0; j < 12; j++) {
                out << asc2_1206[i][j];
            }
        }
        for(int i = 0; i < 95; i++) {
            for(int j = 0; j < 16; j++) {
                out << asc2_1608[i][j];
            }
        }
        for(int i = 0; i < 95; i++) {
            for(int j = 0; j < 36; j++) {
                out << asc2_2412[i][j];
            }
        }
        for(int i = 0; i < 95; i++) {
            for(int j = 0; j < 128; j++) {
                out << asc2_3216[i][j];
            }
        }

        file.close();
    }
}

void MainWindow::on_SerialBtn_clicked()
{

}

void MainWindow::on_refreshSerialBtn_clicked()
{

}

void MainWindow::on_WriteFontBtn_clicked()
{
    if(fontPath.isEmpty()) {
        QMessageBox::information(0, "warning", u8"AscII字库路径为空!");
        return;
    }
}

void MainWindow::on_openAppFileBtn_clicked()
{

}

void MainWindow::on_updateAppBtn_clicked()
{
    QString path = QFileDialog::getOpenFileName(nullptr,
                                                u8"sbc文件",
                                                "/",
                                                "SBC File(*.sbc)");
    if(path.isEmpty()) return;


    //2021_08_20_01_01_00 ~ 2021_08_20_01_59_10; 31 * 60 = 1860
    int hour = 0, min = 0, sec = 0;

    for(hour = 1; hour < 3; hour++) {
        for(min = 0; min < 59; min++) {
            for(sec = 0; sec < 59; sec += 5) {
                //2 * 60 * 12 = 4320
                char sbcPath[36] = {0};
                snprintf(sbcPath, 36, "D:/sbc/2021_08_20_%02d_%02d_%02d.sbc", hour, min, sec);
                QString tmp = sbcPath;
                QFile::copy(path, tmp);
            }
        }
    }
}
